package com.redoor.app.stake.basicdata.controller;

import com.redoor.app.stake.basicdata.model.BussinessTypeEnum;
import com.redoor.app.stake.basicdata.model.LogEnum;
import com.redoor.app.stake.basicdata.service.LogService;
import com.redoornetwork.framework.core.response.ResponseResult;
import com.redoornetwork.framework.core.response.ResultGenerator;
import com.redoor.app.stake.basicdata.model.BaseAssetOperationTrajectory;
import com.redoor.app.stake.basicdata.model.controllerModel.BaseAssetOperationTrajectoryCriteria;
import com.redoor.app.stake.basicdata.service.BaseAssetOperationTrajectoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* Created by wangjunlei on 2018-03-03 19:26:43.
*/
@RestController
@RequestMapping("/base/asset/operation/trajectorys")
public class BaseAssetOperationTrajectoryController {

    @Autowired
    private BaseAssetOperationTrajectoryService baseAssetOperationTrajectoryService;

    @Autowired
    private LogService hsfLogService;

    @PostMapping
    public ResponseResult add(@RequestBody BaseAssetOperationTrajectory baseAssetOperationTrajectory) {
        hsfLogService.addLogToRedis(baseAssetOperationTrajectory,LogEnum.ASSET_TRACE_LOG);
        return ResultGenerator.generatorSuccess();
    }


    @GetMapping
    public ResponseResult getOneSave() {
        List<BaseAssetOperationTrajectory> baseAssetOperationTrajectories = hsfLogService.getLogFromRedis(1, LogEnum.ASSET_TRACE_LOG);
        baseAssetOperationTrajectoryService.saveAll(baseAssetOperationTrajectories);
        return ResultGenerator.generatorSuccess(baseAssetOperationTrajectories);
    }

    @ApiOperation(value = "根据轨迹类型以及主键信息查询轨迹列表", notes = "")
    @PostMapping(value = "/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bussinessTypeEnum", value = "轨迹类型", paramType = "query", dataType = "String", required = true, defaultValue = ""),
            @ApiImplicitParam(name = "assetuuid", value = "主键信息", paramType = "query", dataType = "String", required = true, defaultValue = "")
    })
    public ResponseResult list(BussinessTypeEnum.TRACE_BUSINESS_TYPE bussinessTypeEnum, String assetuuid) {
        List list = baseAssetOperationTrajectoryService.getTraceList(bussinessTypeEnum,assetuuid);
        return ResultGenerator.generatorSuccess(list);
    }
}
